@extends('www/zc-admin/layout')
@section('content')

    <link rel="stylesheet" href="/node_modules/wangeditor/release/wangEditor.min.css">
    <script  src="/node_modules/wangeditor/release/wangEditor.js"></script>

    <div class="main-container">

        @include("/www/zc-admin/left-nav",['typeId'=>$typeId,'nav'=>'set'])

        <div class="main-content">

            <div class="content-anv">
                <span>首页</span>
                <span> ></span>
                <span>项目设置</span>

                <p style="display: inline-block;float:right;padding:3px 10px;background:#999;color:#fff;" onclick="history.back();">返回</p>
            </div>


            <form style="width:700px;margin:auto;padding:20px;background:#fff;" class="form-horizontal" method="post" action="/www/zhongchouAdmin/add_activity" enctype="multipart/form-data" >


                <input type="hidden" name="_token" value="{{csrf_token()}}" id="token">
                <input type="hidden" name="type_id" value="{{$typeId}}">
                <input type="hidden" name="activityId" value="{{$act->activity_id}}">

                <div class="form-group">
                    <label  class="col-sm-2 control-label">项目标题</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" required name="title" VALUE="{{$act->title}}">
                    </div>
                </div>

                <div class="form-group">
                    <label  class="col-sm-2 control-label">筹款金额</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" name="money" required  value="{{$act->money}}">
                    </div>
                </div>

                <div class="form-group">
                    <label  class="col-sm-2 control-label">活动日期</label>
                    <div class="col-sm-5">
                        <input type="date" class="form-control" name="begin_time" required value="{{substr($act->begin_time,0,10)}}">
                    </div>
                    <div class="col-sm-5">
                        <input type="date" class="form-control" name="end_time" required value="{{substr($act->end_time,0,10)}}">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 control-label">发布者姓名</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" name="manager" required value="{{$act->manager}}">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 control-label">分享标题</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" name="share_title" required value="{{$act->share_title}}" >
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 control-label">分享简介</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" name="share_desc" required value="{{$act->share_desc}}">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 control-label">分享图片</label>
                    <div class="col-sm-10">
                        <input type="file" class="form-control" name="share_img" required accept="image/gif,image/jpeg,image/jpg,image/png">
                        <img src="/{{$act->share_img ? $act->share_img : 'www/zc666/images/admin/add-btn.png'}}" class="h100">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 control-label">发布者头像</label>
                    <div class="col-sm-10">
                        <input type="file" class="form-control" name="manager_img" required accept="image/gif,image/jpeg,image/jpg,image/png">
                        <img src="/{{$act->manager_img ? $act->manager_img : 'www/zc666/images/admin/add-btn.png'}}" class="h100">
                    </div>
                </div>
                <div class="form-group hide">
                    <label class="col-sm-2 control-label">广告图片</label>
                    <div class="col-sm-10">
                        <table class="table" id="adimgs">
                            <tr>
                                <td>文件</td>
                                <td>
                                    <span class="btn btn-info" onclick="add_file()">新增</span>
                                </td>
                            </tr>
                            @foreach($act->ad_imgs as $ad)
                                <tr>
                                    <td><img src="/{{$ad}}" style="height:50px;"><input type="hidden" name="adimgs[]" value="{{$ad}}"></td>
                                    <td><span class="btn  btn-danger" onclick="delete_file(this)">删除</span></td>
                                </tr>
                            @endforeach
                            <tr>
                                <td><input type="file" class="form-control" name="ad[]" accept="image/gif,image/jpeg,image/jpg,image/png"></td>
                                <td><span class="btn  btn-danger" onclick="delete_file(this)">删除</span></td>
                            </tr>
                        </table>
                    </div>
                </div>


                <input type="hidden" value="众筹介绍" name="d_title[]">
                <input type="hidden" value="众筹规则" name="d_title[]">

                <div class="form-group hide">
                    <label class="col-sm-2 control-label">众筹介绍</label>
                    <div class="col-sm-10">
                        <div id="editor-desc" class="wang-edit">
                            {!! $act->detail_info[0]['content'] !!}
                        </div>

                        <textarea name="detail[]" id="detailDesc" required class="hide"></textarea>
                    </div>
                </div>

                <div class="form-group hide">
                    <label class="col-sm-2 control-label">众筹规则</label>
                    <div class="col-sm-10">
                        <div id="editor-rule" class="wang-edit">
                            {!! $act->detail_info[1]['content'] !!}
                        </div>

                        <textarea name="detail[]" required class="hide"  id="detailRule"></textarea>
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">

                        {{--<button type="submit" class="btn btn-default">发布项目</button>--}}
                        <p class="btn btn-danger" onclick="publish_activity()">发布项目</p>
                    </div>
                </div>
                <div class="h200"></div>
            </form>





            <table class="hide" id="trcontent">
                <tr>
                    <td>
                        <input type="file" class="form-control" name="ad[]" accept="image/gif,image/jpeg,image/jpg,image/png">
                    </td>
                    <td>
                        <span class="btn  btn-danger" onclick="delete_file(this)">删除</span>
                    </td>
                </tr>
            </table>
        </div>
    </div>

    <style>
        table input[type=file]{
            display: inline-block;
            width:400px;
        }
    </style>


    <script>
        var editDesc,editRule;
        window.onload = function()
        {
            editDesc = create_edit('editor-desc',300);
            editRule = create_edit('editor-rule',300);
        }


        function publish_activity()
        {
            var desc = editDesc.txt.html();
            var rule = editRule.txt.html();
            $('#detailDesc').val(desc);
            $('#detailRule').val(rule);
            $('form').submit();
        }

        function add_file()
        {
            var content = $("#trcontent tbody").html();
            $("#adimgs tbody").append(content);
        }


        function delete_file(obj)
        {
            $(obj).parents('tr').remove();
        }


        function create_edit(id,height){

            var E = window.wangEditor;
            var editor = new E('#'+id);

            editor.customConfig.menus = [
                'head',  // 标题
                'bold',  // 粗体
                'italic',  // 斜体
                //'underline',  // 下划线
                //'strikeThrough',  // 删除线
                'fontSize',
                'foreColor',  // 文字颜色
                'backColor',  // 背景颜色
                'link',  // 插入链接
                'list',  // 列表
                'justify',  // 对齐方式
                'quote',  // 引用
                //'emoticon',  // 表情
                'image',  // 插入图片
                'table',  // 表格
                'video',  // 插入视频
                //'code',  // 插入代码
                'undo',  // 撤销
                'redo'  // 重复
            ];

            editor.customConfig.uploadImgShowBase64 = true   // 使用 base64 保存图片
            editor.customConfig.uploadImgServer = "{{asset('file/saveEditFile')}}";  // 上传图片到服务器
            editor.customConfig.height = height + "px";
            editor.customConfig.uploadImgParams = {
                _token: $('#token').val()
            };

            editor.customConfig.uploadImgParamsWithUrl = true;
            console.log(editor.customConfig.uploadImgParams);
            editor.create();
            return editor;
        }


    </script>
@endsection